package com.example.hotelmanager.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.hotelmanager.entity.Background;
import com.example.hotelmanager.entity.vo.Response;
import com.example.hotelmanager.entity.vo.ResponseMsg;
import com.example.hotelmanager.service.BackgroundService;
import com.example.hotelmanager.utils.JwtUtill;
import lombok.extern.slf4j.Slf4j;
import org.apache.tomcat.util.security.MD5Encoder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import sun.security.provider.MD5;

/**
 * @author :chenjie
 * @date :Created 2022/11/27 15:29
 */
@CrossOrigin//开启跨域访问
@RestController
@Slf4j
public class BackGroundController {
    @Autowired
    private BackgroundService backgroundService;
    @Autowired
    private JwtUtill jwtUtill;
    @PostMapping("/backgroundLogin")
    public Response login(Background backGround){
        log.info(backGround.toString());
        LambdaQueryWrapper<Background> queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.eq(Background::getPassword,backGround.getPassword());
        queryWrapper.eq(Background::getBackId, backGround.getBackId());
        Background backGround1 = backgroundService.getOne(queryWrapper);
        if(backGround1!=null){
            String token = jwtUtill.updateJwt(backGround1.getBackId());
            return (new Response()).success(token);
        }
        return new Response(ResponseMsg.NO_SUCH_USER);
    }
}
